﻿using CSRedis;
using ThresholdAssistant.Tools;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace ThresholdAssistant.Redis
{
    /// <summary>
    /// 
    /// </summary>
    public class CsRedisClientUtil : CSRedisClient, IRedisClient
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="connectionString"></param>
        public CsRedisClientUtil(string connectionString) : base(connectionString)
        {

        }

        #region 同步操作
        /// <summary>
        /// 检查缓存Key是否存在
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool ContainsKey(string key) => base.Exists(key);

        /// <summary>
        /// 批量删除缓存Key
        /// </summary>
        /// <param name="key"></param>
        /// <returns>删除成功的记录数量</returns>
        public bool DeleteKey(string key) => base.Del(key) > 0;

        /// <summary>
        /// 批量删除缓存Key
        /// </summary>
        /// <param name="keys">key列表</param>
        /// <returns>删除成功的记录数量</returns>
        public bool DeleteKey(params string[] keys) => base.Del(keys) > 0;

        /// <summary>
        /// 重新命名key
        /// </summary>
        /// <param name="key">就的redis key</param>
        /// <param name="newKey">新的redis key</param>
        /// <returns></returns>
        public bool RenameKey(string key, string newKey) => base.Rename(key, newKey);

        /// <summary>
        /// 设置缓存过期
        /// </summary>
        /// <param name="key"></param>
        /// <param name="timeoutSeconds"></param>
        public bool SetExpire(string key, int timeoutSeconds) => base.Expire(key, timeoutSeconds);

        /// <summary>
        /// 获取String类型的缓存
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public string StringGet(string key) => base.Get(key);

        /// <summary>
        /// 获取String类型的缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        public T StringGet<T>(string key)
        {
            T result = default;
            try
            {
                byte[] btyes = base.Get<byte[]>(key);
                return ProtoBufConvert.DeserializeObject<T>(btyes);
            }
            catch (Exception)
            {

            }
            return result;

        }

        /// <summary>
        /// 设置String类型缓存
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expireSeconds"></param>
        /// <returns></returns>
        public bool StringSet(string key, string value, int expireSeconds = -1) => base.Set(key, value, expireSeconds);

        /// <summary>
        /// 设置String类型缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expireSeconds"></param>
        /// <returns></returns>
        public bool StringSet<T>(string key, T value, int expireSeconds = -1)
        {
            bool isSuccess = false;
            try
            {
                byte[] bytes = ProtoBufConvert.SerializeObject(value);
                isSuccess = base.Set(key, bytes, expireSeconds);
            }
            catch (Exception)
            {

            }
            return isSuccess;
        }

        /// <summary>
        /// 原子性递增
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value">增量：可以为负数</param>
        /// <param name="expireSeconds">缓存过期时间(单位：秒)</param>
        /// <returns>增长后的值</returns>
        public long StringIncrement(string key, long value = 1, int expireSeconds = -1)
        {
            var newValue = base.IncrBy(key, value);
            SetExpire(key, expireSeconds);
            return newValue;
        }

        /// <summary>
        /// 原子性递增
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value">增量：可以为负数</param>
        /// <returns>增长后的值</returns>
        public long StringIncrementNoExpire(string key, long value = 1)
        {
            return base.IncrBy(key, value);
        }

        /// <summary>
        /// 原子性递增 绝对过期时间
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value">增量：可以为负数</param>
        /// <param name="expireSeconds">过期时间</param>
        /// <returns>增长后的值</returns>
        public long StringIncrementByAbsoluteExpire(string key, long value = 1, int expireSeconds = -1)
        {
            var newValue = base.IncrBy(key, value);
            if (newValue == value)
            {
                SetExpire(key, expireSeconds);
            }
            return newValue;
        }

        /// <summary>
        /// 分布式锁
        /// </summary>
        /// <param name="key"></param>
        /// <param name="timeoutSeconds">缓存时间(单位：秒)</param>
        /// <param name="autoDelay">是否自动延迟</param>
        /// <returns></returns>
        public CSRedisClientLock Lockup(string key, int timeoutSeconds = -1, bool autoDelay = true) => base.Lock(key, timeoutSeconds, autoDelay);

        /// <summary>
        /// 检查hash键是否存在
        /// </summary>
        /// <param name="key"></param>
        /// <param name="hashField"></param>
        /// <returns></returns>
        public bool ContainsHashKey(string key, string hashField) => base.HExists(key, hashField);

        /// <summary>
        /// 移除hash中的某值
        /// </summary>
        /// <param name="key"></param>
        /// <param name="hashField"></param>
        /// <returns></returns>
        public bool DeleteHash(string key, string hashField) => base.HDel(key, hashField) > 0;

        /// <summary>
        /// 移除hash中的某值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="hashFields"></param>
        /// <returns></returns>
        public long DeleteHash(string key, params string[] hashFields) => base.HDel(key, hashFields);

        /// <summary>
        /// 获取Hash值
        /// </summary>
        /// <param name="key"></param>
        /// <param name="hashField"></param>
        /// <returns></returns>
        public string HashGet(string key, string hashField) => base.HGet(key, hashField);

        /// <summary>
        /// 获取Hash值
        /// </summary>
        /// <param name="key"></param>
        /// <param name="hashField"></param>
        /// <returns></returns>
        public T HashGet<T>(string key, string hashField)
        {
            T result = default;
            try
            {
                byte[] bytes = base.HGet<byte[]>(key, hashField);
                result = ProtoBufConvert.DeserializeObject<T>(bytes);
            }
            catch (Exception)
            {

            }
            return result;
        }

        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <param name="key"></param>
        /// <param name="hashField"></param>
        /// <param name="value"></param>
        /// <param name="timeoutSeconds"></param>
        /// <returns></returns>
        public bool HashSet(string key, string hashField, string value, int timeoutSeconds = -1)
        {
            bool keyExists = ContainsKey(key);//缓存是否存在
            bool isSuccess = base.HSet(key, hashField, value);
            if (keyExists)
            {
                SetExpire(key, timeoutSeconds);
            }
            return isSuccess;
        }

        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <param name="key"></param>
        /// <param name="hashField"></param>
        /// <param name="value"></param>
        /// <param name="timeoutSeconds"></param>
        /// <returns></returns>
        public bool HashSet<T>(string key, string hashField, T value, int timeoutSeconds = -1)
        {
            bool isSuccess = false;
            try
            {
                bool keyExists = ContainsKey(key);//缓存是否存在
                byte[] bytes = ProtoBufConvert.SerializeObject(value);
                isSuccess = base.HSet(key, hashField, bytes);
                if (keyExists)
                {
                    SetExpire(key, timeoutSeconds);
                }
            }
            catch
            {
            }
            return isSuccess;
        }

        /// <summary>
        /// 原子性递增
        /// </summary>
        /// <param name="key"></param>
        /// <param name="hashField"></param>
        /// <param name="value">增量：可以为负数</param>
        /// <param name="timeoutSeconds">缓存过期时间（单位：秒）</param>
        /// <returns>增长后的值</returns>
        public long HashIncrement(string key, string hashField, long value = 1, int timeoutSeconds = -1)
        {
            long increment = 0;
            try
            {
                bool keyExists = ContainsKey(key);//缓存是否存在
                increment = base.HIncrBy(key, hashField, value);
                if (keyExists)
                {
                    SetExpire(key, timeoutSeconds);
                }
            }
            catch
            {
            }
            return increment;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="timeoutSeconds"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool SetNx(string key, object value, int timeoutSeconds)
        {
            bool isSuccess = false;
            try
            {
                isSuccess = base.SetNx(key, value);
                if (isSuccess)
                {
                    //设置缓存过期时间
                    SetExpire(key, timeoutSeconds);
                }
            }
            catch (Exception)
            {
                DeleteKey(key);
            }
            return isSuccess;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="timeoutSeconds"></param>
        /// <returns></returns>
        public RedisClientLockNx LockNx(string key, int timeoutSeconds = 5)
        {
            key = $"RedisClientLockNx:{key}";
            RedisClientLockNx lockClient = null;
            try
            {
                bool isSuccess = SetNx(key, 1, timeoutSeconds);
                if (isSuccess)
                {
                    //创建客户端
                    lockClient = new RedisClientLockNx(key, this);
                }
            }
            catch (Exception)
            {
                DeleteKey(key);
            }
            return lockClient;
        }

        /// <summary>
        /// 分布式等待锁
        /// </summary>
        /// <param name="lockKey"></param>
        /// <param name="timeoutSeconds"></param>
        /// <param name="autoDelay">是否自动延长超时时间</param>
        /// <returns></returns>
        public new CSRedisClientLock Lock(string lockKey, int timeoutSeconds, bool autoDelay = false)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(lockKey))
                {
                    return null;
                }
                return base.Lock(lockKey, timeoutSeconds, autoDelay);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 消息发布
        /// </summary>
        /// <param name="channel">频道名</param>
        /// <param name="message">消息内容</param>
        /// <returns></returns>
        public new long PublishNoneMessageId(string channel, string message)
        {
            return base.PublishNoneMessageId(channel, message);
        }

        /// <summary>
        /// 将一个或多个值插入到列表头部
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="value">一个或多个值</param>
        /// <returns>执行 LPUSH 命令后，列表的长度</returns>
        public new long LPush<T>(string key, params T[] value)
        {
            if (value != null && value.Length > 0)
            {
                return base.LPush(key, value);
            }

            return 0L;
        }

        /// <summary>
        /// 移出并获取列表的第一个元素
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public new string LPop(string key)
        {
            return base.LPop(key);
        }

        /// <summary>
        /// 移出并获取列表的第一个元素
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public new T LPop<T>(string key)
        {
            return base.LPop<T>(key);
        }

        /// <summary>
        /// 移出并获取列表的最后一个元素
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public new string RPop(string key)
        {
            return base.RPop(key);
        }

        /// <summary>
        /// 移出并获取列表的最后一个元素
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public new T RPop<T>(string key)
        {
            return base.RPop<T>(key);
        }

        /// <summary>
        /// 对一个列表进行修剪，让列表只保留指定区间内的元素，不在指定区间之内的元素都将被删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="start"> 开始位置，0表示第一个元素，-1表示最后一个元素</param>
        /// <param name="stop">结束位置，0表示第一个元素，-1表示最后一个元素</param>
        /// <returns></returns>
        public bool LTrim<T>(string key, long start, long stop)
        {
            return base.LTrim(key, start, stop);
        }

        /// <summary>
        /// 获取列表长度
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public new long LLen(string key)
        {
            return base.LLen(key);
        }

        /// <summary>
        /// 获取列表指定范围内的元素
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">不含prefix前辍</param>
        /// <param name="start">开始位置，0表示第一个元素，-1表示最后一个元素</param>
        /// <param name="stop"> 结束位置，0表示第一个元素，-1表示最后一个元素</param>
        /// <returns></returns>
        public new string[] LRange(string key, long start, long stop)
        {
            return base.LRange(key, start, stop);
        }

        /// <summary>
        /// 获取列表指定范围内的元素
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">不含prefix前辍</param>
        /// <param name="start">开始位置，0表示第一个元素，-1表示最后一个元素</param>
        /// <param name="stop"> 结束位置，0表示第一个元素，-1表示最后一个元素</param>
        /// <returns></returns>
        public new T[] LRange<T>(string key, long start, long stop)
        {
            return base.LRange<T>(key, start, stop);
        }

        #endregion

        #region 异步操作
        /// <summary>
        /// 检查缓存Key是否存在
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public async Task<bool> ContainsKeyAsync(string key) => await base.ExistsAsync(key);

        /// <summary>
        /// 批量删除缓存Key
        /// </summary>
        /// <param name="key"></param>
        /// <returns>删除成功的记录数量</returns>
        public async Task<bool> DeleteKeyAsync(string key) => await base.DelAsync(key) > 0;

        /// <summary>
        /// 批量删除缓存Key
        /// </summary>
        /// <param name="keys">key列表</param>
        /// <returns>删除成功的记录数量</returns>
        public async Task<bool> DeleteKeyAsync(params string[] keys) => await base.DelAsync(keys) > 0;

        /// <summary>
        /// 重新命名key
        /// </summary>
        /// <param name="key">就的redis key</param>
        /// <param name="newKey">新的redis key</param>
        /// <returns></returns>
        public async Task<bool> RenameKeyAsync(string key, string newKey) => await base.RenameAsync(key, newKey);

        /// <summary>
        /// 设置缓存过期
        /// </summary>
        /// <param name="key"></param>
        /// <param name="timeoutSeconds"></param>
        public async Task<bool> SetExpireAsync(string key, int timeoutSeconds) => await base.ExpireAsync(key, timeoutSeconds);

        /// <summary>
        /// 获取String类型的缓存
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public async Task<string> StringGetAsync(string key) => await base.GetAsync(key);

        /// <summary>
        /// 获取String类型的缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        public async Task<T> StringGetAsync<T>(string key)
        {
            T result = default;
            try
            {
                byte[] btyes = await base.GetAsync<byte[]>(key);
                return ProtoBufConvert.DeserializeObject<T>(btyes);
            }
            catch (Exception)
            {

            }
            return result;

        }

        /// <summary>
        /// 设置String类型缓存
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expireSeconds"></param>
        /// <returns></returns>
        public async Task<bool> StringSetAsync(string key, object value, int expireSeconds = -1) => await base.SetAsync(key, value, expireSeconds);

        /// <summary>
        /// 设置String类型缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expireSeconds"></param>
        /// <returns></returns>
        public async Task<bool> StringSetAsync<T>(string key, T value, int expireSeconds = -1)
        {
            bool isSuccess = false;
            try
            {
                byte[] bytes = ProtoBufConvert.SerializeObject(value);
                isSuccess = await base.SetAsync(key, bytes, expireSeconds);
            }
            catch (Exception)
            {

            }
            return isSuccess;
        }

        /// <summary>
        /// 原子性递增
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value">增量：可以为负数</param>
        /// <param name="expireSeconds">缓存过期时间(单位：秒)</param>
        /// <returns>增长后的值</returns>
        public async Task<long> StringIncrementAsync(string key, long value = 1, int expireSeconds = -1)
        {
            var newValue = await base.IncrByAsync(key, value);
            await SetExpireAsync(key, expireSeconds);
            return newValue;
        }

        /// <summary>
        /// 检查hash键是否存在
        /// </summary>
        /// <param name="key"></param>
        /// <param name="hashField"></param>
        /// <returns></returns>
        public async Task<bool> ContainsHashKeyAsync(string key, string hashField) => await base.HExistsAsync(key, hashField);

        /// <summary>
        /// 移除hash中的某值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="hashField"></param>
        /// <returns></returns>
        public async Task<bool> DeleteHashAsync(string key, string hashField) => await base.HDelAsync(key, hashField) > 0;

        /// <summary>
        /// 移除hash中的某值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="hashFields"></param>
        /// <returns></returns>
        public async Task<bool> DeleteHashAsync(string key, params string[] hashFields) => await base.HDelAsync(key, hashFields) > 0;

        /// <summary>
        /// 获取Hash值
        /// </summary>
        /// <param name="key"></param>
        /// <param name="hashField"></param>
        /// <returns></returns>
        public async Task<string> HashGetAsync(string key, string hashField) => await base.HGetAsync(key, hashField);

        /// <summary>
        /// 获取Hash值
        /// </summary>
        /// <param name="key"></param>
        /// <param name="hashField"></param>
        /// <returns></returns>
        public async Task<T> HashGetAsync<T>(string key, string hashField)
        {
            T result = default;
            try
            {
                byte[] bytes = await base.HGetAsync<byte[]>(key, hashField);
                result = ProtoBufConvert.DeserializeObject<T>(bytes);
            }
            catch (Exception)
            {

            }
            return result;
        }

        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <param name="key"></param>
        /// <param name="hashField"></param>
        /// <param name="value"></param>
        /// <param name="timeoutSeconds"></param>
        /// <returns></returns>
        public async Task<bool> HashSetAsync(string key, string hashField, string value, int timeoutSeconds = -1)
        {
            bool keyExists = await ContainsKeyAsync(key);//缓存是否存在
            bool isSuccess = await base.HSetAsync(key, hashField, value);
            if (keyExists)
            {
                await SetExpireAsync(key, timeoutSeconds);
            }
            return isSuccess;
        }

        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <param name="key"></param>
        /// <param name="hashField"></param>
        /// <param name="value"></param>
        /// <param name="timeoutSeconds"></param>
        /// <returns></returns>
        public async Task<bool> HashSetAsync<T>(string key, string hashField, T value, int timeoutSeconds = -1)
        {
            bool isSuccess = false;
            try
            {
                bool keyExists = await ContainsKeyAsync(key);//缓存是否存在
                byte[] bytes = ProtoBufConvert.SerializeObject(value);
                isSuccess = await base.HSetAsync(key, hashField, bytes);
                if (keyExists)
                {
                    await SetExpireAsync(key, timeoutSeconds);
                }
            }
            catch
            {
            }
            return isSuccess;
        }

        /// <summary>
        /// 原子性递增
        /// </summary>
        /// <param name="key"></param>
        /// <param name="hashField"></param>
        /// <param name="value">增量：可以为负数</param>
        /// <param name="timeoutSeconds">缓存过期时间（单位：秒）</param>
        /// <returns>增长后的值</returns>
        public async Task<long> HashIncrementAsync(string key, string hashField, long value = 1, int timeoutSeconds = -1)
        {
            long increment = 0;
            try
            {
                bool keyExists = await ContainsKeyAsync(key);//缓存是否存在
                increment = await base.HIncrByAsync(key, hashField, value);
                if (keyExists)
                {
                    await SetExpireAsync(key, timeoutSeconds);
                }
            }
            catch
            {
            }
            return increment;
        }

        /// <summary>
        /// 原子性递增
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value">增量：可以为负数</param>
        /// <returns>增长后的值</returns>
        public async Task<long> StringIncrementNoExpireAsync(string key, long value = 1)
        {
            return await base.IncrByAsync(key, value);
        }

        /// <summary>
        /// 原子性递增 绝对过期时间
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value">增量：可以为负数</param>
        /// <param name="expireSeconds">过期时间</param>
        /// <returns>增长后的值</returns>
        public async Task<long> StringIncrementByAbsoluteExpireAsync(string key, long value = 1, int expireSeconds = -1)
        {
            var newValue = await base.IncrByAsync(key, value);
            if (newValue == value)
            {
                SetExpire(key, expireSeconds);
            }
            return newValue;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="timeoutSeconds"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public async Task<bool> SetNxAsync(string key, object value, int timeoutSeconds)
        {
            bool isSuccess = false;
            try
            {
                isSuccess = await base.SetNxAsync(key, value);
                if (isSuccess)
                {
                    //设置缓存过期时间
                    await SetExpireAsync(key, timeoutSeconds);
                }
            }
            catch (Exception)
            {
                await DeleteKeyAsync(key);
            }
            return isSuccess;
        }

        /// <summary>
        /// 消息发布
        /// </summary>
        /// <param name="channel">频道名</param>
        /// <param name="message">消息内容</param>
        /// <returns></returns>
        public new async Task<long> PublishNoneMessageIdAsync(string channel, string message)
        {
            return await base.PublishNoneMessageIdAsync(channel, message);
        }

        /// <summary>
        /// 将一个或多个值插入到列表头部
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="value">一个或多个值</param>
        /// <returns>执行 LPUSH 命令后，列表的长度</returns>
        public new async Task<long> LPushAsync<T>(string key, params T[] value)
        {
            return await base.LPushAsync(key, value);
        }

        /// <summary>
        /// 对一个列表进行修剪，让列表只保留指定区间内的元素，不在指定区间之内的元素都将被删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="start"> 开始位置，0表示第一个元素，-1表示最后一个元素</param>
        /// <param name="stop">结束位置，0表示第一个元素，-1表示最后一个元素</param>
        /// <returns></returns>
        public async Task<bool> LTrimAsync<T>(string key, long start, long stop)
        {
            return await base.LTrimAsync(key, start, stop);
        }

        /// <summary>
        /// 移出并获取列表的第一个元素
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public new async Task<string> LPopAsync(string key)
        {
            return await base.LPopAsync(key);
        }

        /// <summary>
        /// 移出并获取列表的第一个元素
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public new async Task<T> LPopAsync<T>(string key)
        {
            return await base.LPopAsync<T>(key);
        }

        /// <summary>
        /// 移出并获取列表的最后一个元素
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public new async Task<string> RPopAsync(string key)
        {
            return await base.RPopAsync(key);
        }

        /// <summary>
        /// 移出并获取列表的最后一个元素
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public new async Task<T> RPopAsync<T>(string key)
        {
            return await base.RPopAsync<T>(key);
        }

        /// <summary>
        /// 获取列表长度
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public new async Task<long> LLenAsync(string key)
        {
            return await base.LLenAsync(key);
        }

        /// <summary>
        /// 获取列表指定范围内的元素
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">不含prefix前辍</param>
        /// <param name="start">开始位置，0表示第一个元素，-1表示最后一个元素</param>
        /// <param name="stop"> 结束位置，0表示第一个元素，-1表示最后一个元素</param>
        /// <returns></returns>
        public new async Task<string[]> LRangeAsync(string key, long start, long stop)
        {
            return await base.LRangeAsync(key, start, stop);
        }

        /// <summary>
        /// 获取列表指定范围内的元素
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">不含prefix前辍</param>
        /// <param name="start">开始位置，0表示第一个元素，-1表示最后一个元素</param>
        /// <param name="stop"> 结束位置，0表示第一个元素，-1表示最后一个元素</param>
        /// <returns></returns>
        public new async Task<T[]> LRangeAsync<T>(string key, long start, long stop)
        {
            return await base.LRangeAsync<T>(key, start, stop);
        }

        /// <summary>
        /// 获取Hash所有键和值
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public async Task<Dictionary<string, string>> HashGetAllAsync(string key) => await base.HGetAllAsync(key);


        /// <summary>
        /// 获取存储在哈希表中多个字段的值
        /// </summary>
        /// <param name="key"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public async Task<string[]> HashGetMultipleAsync(string key, params string[] fields) => await base.HMGetAsync(key, fields);

        /// <summary>
        /// 设置哈希表- 同时将多个 field-value (域-值)对设置到哈希表 key 中
        /// </summary>
        /// <param name="key"></param>
        /// <param name="keyValues"> key1 value1 [key2 value2]</param>
        /// <returns></returns>
        public async Task<bool> HashSetMultipleAsync(string key, params object[] keyValues) => await base.HMSetAsync(key, keyValues);

        #endregion
    }
}
